package com.hospital.common.core.utils;

import com.hospital.common.core.exception.ExceptionHelpEnum;
import com.hospital.common.core.result.ErrorTip;
import com.hospital.common.core.result.SuccessTip;
import com.hospital.common.core.result.Tip;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @Author: Yeman
 * @Date: 2023-10-19-10:32
 * @Description:
 */
@Service
@Slf4j
public class ValidatedCheck {
    /**
     * 参数校验
     *
     * @param object
     * @return
     */
    public static Tip validateFunc(Object object) {
        try {
            Map<String, String> validateobject = BeanValidator.validateobject(object);
            if (validateobject != null && validateobject.entrySet().size() > 0) {
                String errStr = "";
                for (Map.Entry<String, String> entry : validateobject.entrySet()) {
                    errStr = errStr + entry.getKey() + "->" + entry.getValue() + ";";
                }
                ExceptionHelpEnum.HOS_ERROR_PARAM.setMessage(errStr);
                return new ErrorTip(ExceptionHelpEnum.HOS_ERROR_PARAM);
            }

        } catch (Exception e) {
            ExceptionHelpEnum.HOS_ERROR_PARAM.setMessage(e.getMessage());
            return new ErrorTip(ExceptionHelpEnum.HOS_ERROR_PARAM);
        }
        return new SuccessTip();
    }
}
